﻿using System;
using Mbs.Messaging;
using NUnit.Framework;

namespace MBTest
{
    [TestFixture]
    public class UnsubscriberTest
    {
        [Test]
        public void Test()
        {
            using (var MB = new MessageBus())
            {
                var Unsubscriber = MB.Subscribe<int, string, bool>(
                    (s, e) =>
                    {
                        Console.WriteLine(e);
                    },
                    (s, e) =>
                    {
                        Console.WriteLine(e);
                    },
                    (s, e) =>
                    {
                        Console.WriteLine(e);
                    });

                

                MB.Publish(true);
                MB.Publish("How are you!");
                MB.Publish(5);

                Unsubscriber.Dispose();
                //下面的代码将不会执行
                MB.Publish(true);
                MB.Publish("How are you!");
                MB.Publish(5);

            }
        }

        [Test]
        public void Test2()
        {
            using (var MB = new MessageBus())
            {
                var Unsubscriber = MB.Subscribe<int, string, bool>(
                   "int", (s, e) =>
                    {
                        Console.WriteLine(e);
                    },
                    "string", (s, e) =>
                    {
                        Console.WriteLine(e);
                    },
                    "bool", (s, e) =>
                    {
                        Console.WriteLine(e);
                    });

                MB.Publish("bool",true);
                MB.Publish("string","How are you!");
                MB.Publish("int",5);

                Unsubscriber.Dispose();
                //下面的代码将不会执行
                MB.Publish("bool", true);
                MB.Publish("string", "How are you!");
                MB.Publish("int", 5);

            }
        }

       
        [Test]
        public void Simaple2()
        {
            var MB = new MessageBus();
            var unsubscriber = MB.Subscribe<int>((s, e) => Console.WriteLine(e));
            MB.Publish(521);
            unsubscriber.Dispose();
        }
    }
}
